<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
    </style>
</head>

<body>
    <div id="app">
        <book></book>
        <hr />
        <asyncbook></asyncbook>
    </div>
</body>

</html>
<script src="./js/vue.global.js"></script>
<script>
    const { createApp, defineAsyncComponent } = Vue;

    // 同步组件
    let book = {
        template: `<div>书籍组件（同步组件）</div>`,
        created() {
            console.log("book组件");
        }
    }

    // 异步组件：

    let asyncbook = defineAsyncComponent(() => {
        return new Promise(function (resolve, reject) {
            setTimeout(function () {
                resolve({
                    template: `<div>书籍组件（异步组件）</div>`,
                    created() {
                        console.log("asyncbook组件");
                    }
                })
            }, 2000);
        });
    })


    let app = createApp({
        components: {
            book, asyncbook
        }
    })

    app.mount("#app");



</script>